#ifndef _ILOG_H_
#define _ILOG_H_

#include <stdarg.h>

#define LOG_LABEL_SIZE	64
#define LOG_BUFFER_SIZE	1024
#define LOG_PATH_SIZE	128

#define LV_FATAL	0	/* system is unusable */
#define LV_ERROR	1	/* error conditions */
#define LV_SYS		2	/* system info */
#define LV_WARN		3	/* warning conditions */
#define LV_INFO		4	/* informational message */
#define LV_DEBUG	5	/* debug level message */
#define LV_NUM		6

typedef struct ILOG {
	unsigned int	level;
	unsigned int	bufsz;
	int				fd;
	char			path[LOG_PATH_SIZE];
} ILOG;

ILOG * ilog_new(const char * path, unsigned int level, unsigned int bufsz);
int ilog_free(ILOG * p);

//level ok return 1 else return 0
int lvok(ILOG * p, unsigned int level);
//logit to users
void logit(ILOG * p, unsigned int level, const char * func, const char *fmt, ...);
//raw logit with msg and no level check
void rlogit(ILOG * p, unsigned int level, const char * func, const char * msg);
//va_list logit with fmt args and no level check
void vlogit(ILOG * p, unsigned int level, const char * func, const char * fmt, va_list argp);

#ifndef NILOG
	#define	ILOG_NEW(path, level, bufsz)	ilog_new(path, level, bufsz)
	#define	ILOG_FREE(p)					ilog_new(p)
	#define ILOGIT(p, level, fmt, ...)		logit(p, level, __func__, fmt, ## __VA_ARGS__)
#else
	#define	ILOG_NEW(path, level, bufsz)
	#define	ILOG_FREE(p)
	#define ILOGIT(p, fmt, ...)
#endif

/*
#define ILOG_FATAL(p, fmt, ...)				logit(p, LV_FATAL, __func__, fmt, ## __VA_ARGS__)
#define ILOG_ERROR(p, fmt, ...)				logit(p, LV_ERROR, __func__, fmt, ## __VA_ARGS__)
#define ILOG_SYS(p, fmt, ...)				logit(p, LV_SYS, __func__, fmt, ## __VA_ARGS__)
#define ILOG_WARN(p, fmt, ...)				logit(p, LV_WARN, __func__, fmt, ## __VA_ARGS__)
#define ILOG_INFO(p, fmt, ...)				logit(p, LV_INFO, __func__, fmt, ## __VA_ARGS__)
#define ILOG_DEBUG(p, fmt, ...)				logit(p, LV_DEBUG, __func__, fmt, ## __VA_ARGS__)
*/
#define ILOG_FATAL(p, fmt, ...)				ILOGIT(p, LV_FATAL, fmt, ## __VA_ARGS__)
#define ILOG_ERROR(p, fmt, ...)				ILOGIT(p, LV_ERROR, fmt, ## __VA_ARGS__)
#define ILOG_SYS(p, fmt, ...)				ILOGIT(p, LV_SYS, fmt, ## __VA_ARGS__)
#define ILOG_WARN(p, fmt, ...)				ILOGIT(p, LV_WARN, fmt, ## __VA_ARGS__)
#define ILOG_INFO(p, fmt, ...)				ILOGIT(p, LV_INFO, fmt, ## __VA_ARGS__)
#define ILOG_DEBUG(p, fmt, ...)				ILOGIT(p, LV_DEBUG, fmt, ## __VA_ARGS__)
#endif
